<include file="Public/header" />
<include file="Public/menu" />
<style>
    .edit-list{
        display:none;
        width: 78px;position:absolute;top:-1px;left:78px;background:white; border: 1px solid #666
    }
    .edit-list.active{
        display:block;
        border-color: #666666;
        color: #3367AC;
        z-index: 999;
        margin-top: 1px;
        padding-right: 5px;

    }
    .order-edit{
        padding-left:0;
        margin: 3px 0;
    }
    .order-edit li{
        list-style-type:none;
        cursor: pointer;
        padding: 0 4px;
        float: none;
        width: auto;
        text-align: right;
        font-size: 12px;
        line-height: 23px;
        height: 23px;
    }
    .order-edit li a{


        font-size: 12px;
    }
    .cur{
      border-bottom: 1px #cccccc dotted;
        padding-bottom: 3px;
    }
    .handle-order{
        width: 79px;
    }
    .handle-order.active{
        background:white;

        border: 1px #666666 solid;
        border-right: 0 none;
        padding: 2px 8px 2px 4px;
        font-size: 13px;
        z-index: 10000;
        color: #3367ac;
    }

    .handle-order.active b{
        background: url('/Public/images/arrow-right.gif') no-repeat scroll 50% 50%;
        display: inline-block;
        width: 10px;
        height: 10px;
        vertical-align: center;

    }
    .handle-order b {
        background: url('/Public/images/arrow-down.gif') no-repeat scroll 50% 50%;
        display: inline-block;
        width: 10px;
        height: 10px;
        margin-left: 4px;
        vertical-align: center;
    }


</style>
<!-- 内容页 -->
<div class="content-wrapper">
    <!-- 面包屑 -->
    <section class="content-header">
        <h1>
            门店订单
            <small>订单列表</small>
        </h1>

    </section>

    <!-- 内容 -->
    <section class="content">

        <div class="row"><div class="col-md-12"><div class="nav-tabs-custom">
            <ul class="nav nav-tabs">
                <li <if condition="I('get.view') eq 0" >class="active"</if>><a href="{:U(orders/orderList,array('view'=>0))}">待发货</a></li>
                <li <if condition="I('get.view') eq 1" >class="active"</if> ><a href="{:U(orders/orderList,array('view'=>1))}" >已发货</a></li>
                <li <if condition="I('get.view') eq 2" >class="active"</if>><a href="{:U(orders/orderList,array('view'=>2))}" >已收货</a></li>
                <li <if condition="I('get.view') eq 3" >class="active"</if>><a href="{:U(orders/orderList,array('view'=>3))}" >待支付</a></li>
                <li <if condition="I('get.view') eq 4" >class="active"</if>><a href="{:U(orders/orderList,array('view'=>4))}" >已作废</a></li>
                <li <if condition="I('get.view') eq 5" >class="active"</if>><a href="{:U(orders/orderList,array('view'=>5))}" >已完成</a></li>
                <!--<li <if condition="I('get.view') eq 6" >class="active"</if>><a href="{:U(orders/orderList,array('view'=>6))}" >门店自提</a></li>-->
                <li <if condition="I('get.view') eq 6" >class="active"</if>><a href="{:U(orders/orderList,array('view'=>6))}" >全部</a></li>


                <li class="pull-right header"></li>
            </ul>
            <div class="tab-content">
                <div class="box-header">
                    <h3 class="box-title"></h3>


                    <div class="form-inline pull-right">
                        <form action="" method="get" pjax-container="" id="search_form">
                            <input id="p" name="p" type="hidden" value="1" />
                            <fieldset>
                                <select class="form-control" id="isOrderChange"  onchange="showSelectType(this)" name="select" style="height: 30px; font-size: 12px;">
                                    <option value="">--请选择--</option>
                                    <option value="local_name">门店名称</option>
                                    <option value="order_id">订单号</option>
                                    <option value="ship_name">收货人</option>
                                    <option value="createtime">订单时间</option>
                                    <option value="ship_mobile">电话</option>
                                </select>
                                <input id="select_type" name="select_type" type="hidden" value="{$_GET['select_type']}" />

                                <div class="input-group input-group-sm isOrderChangeDate" style="display: none">
                                    <div class="input-group input-group-sm date form_datetime">

                                        <input id="begin_time" name="begin_time" class="form-control" type="text" value="{$_GET['begin_time']}" readonly/>
                                    </div>
                                    <div class="btn-group">-</div>
                                    <div class="input-group input-group-sm date">
                                        <input id="end_time" name="end_time" class="form-control" type="text" value="{$_GET['end_time']}" readonly/>
                                    </div>
                                </div>

                                <div class="input-group input-group-sm">
                                    <div class="input-group input-group-sm">
                                        <input type="text" class="form-control"  placeholder="搜索" id="search_val" name="search_val" value="{$_GET['search_val']}">
                                    </div>
                                </div>
                                <div class="input-group input-group-sm">
                                    <div class="input-group-btn">
                                        <button type="submit" class="btn btn-primary"><i class="fa fa-search"></i></button>
                                    </div>
                                </div>
                            </fieldset>
                        </form>
                    </div>





                    <div class="btn-group pull-right" style="margin-right: 10px">
                        <a href="javascript:void(0);" target="_blank" onclick="ept();" class="btn btn-sm btn-warning"  style="margin-right: 5px;"><i class="fa fa-download"></i>&nbsp;&nbsp;导出订单</a>
                        <a href="{:U('Orders/exprotAllOrder',['view'=>I('get.view',0,'intval')])}"  class="btn btn-sm btn-warning"><i class="fa fa-download"></i>&nbsp;&nbsp;导出{$isDes}全部订单</a>

                    </div>
                </div>
                <form action="/Manage/orders/eExcel" method="post" id="eid">
                    <div class="tab-pane active" id="tab_0">
                    <div class="box">

                        <!-- /.box-header -->
                        <div class="box-body table-responsive no-padding">
                            <table class="table table-hover table-view-list" style="overflow-x:scroll;margin-bottom:35px;">
                                <tbody><tr>
                                    <th><input type="checkbox" id="SelectAll" onclick="selectAll();" class="grid-select-all"></th>
                                    <th>ID</th>
                                    <th>门店</th>
                                    <th>是否自提</th>
                                    <th>是否退款</th>
                                    <th>操作</th>

                                    <th>下单时间</th>
                                    <th>配送方式</th>
                                    <th>配送时间</th>
                                    <th>客户备注</th>
                                    <th>订单备注</th>
                                    <th>会员名称</th>
                                    <th>支付方式</th>
                                    <th>收货人</th>
                                    <th>收货人手机</th>
                                    <th>配送费用</th>
                                    <th>订单总额</th>
                                    <th>付款状态</th>
                                    <th>发货状态</th>



                                </tr>
                                <volist name="payList" id="item">
                                <tr>
                                    <td><input type="checkbox" name="checkName[]" class="grid-item" value="{$item.order_id}"></td>

                                    <td><a href="{$item.detailurl}">{$item.order_id}</a></td>
                                    <td>{$item.local_name}</td>
                                    <td>{$item.is_zt}</td>
                                    <td>{$item.isback}</td>
                                    <td width="150px">
                                        <div style="position:relative;cursor:pointer">
                                           <div class='handle-order' style="position:relative;cursor:pointer">订单详情<if condition="$item.sell_later neq ''"><br><span style="color: #ff0000">{$item.sell_later}</span></if><b></b></div>
                                                {$item.action}
                                        </div>
                                    </td>

                                    <td>{$item.time}</td>
                                    <td>{$item.shipping}</td>
                                    <td>{$item.ship_time}</td>

                                    <td style="width: 200px;">{$item.memo}</td>
                                    <td style="width: 200px;">{$item.mark}</td>

                                    <td>{$item.login_account}</td>
                                    <td>{$item.payment}</td>

                                    <td>{$item.ship_name}</td>
                                    <td>{$item.ship_mobile}</td>

                                    <td>￥{$item.cost_freight}</td>
                                    <td>￥{$item.total_amount}</td>
                                    <td>{$item.pay_status}</td>
                                    <td>{$item.ship_status}</td>


                                </tr>
                                    </volist>
                                </tbody></table>
                        </div>
                        <div class="box-footer clearfix">

                            <a class="btn btn-sm btn-primary grid-refresh" style="float: right" onclick="javascript:location.replace(location.href);"><i class="fa fa-refresh"></i></a>
                            {$page}


                        </div>
                        <!-- /.box-body -->
                    </div>
                </div>

                </form>
                <div class="tab-pane " id="tab_{$k}">
                    <div class="box">
                        <div class="box-body table-responsive no-padding">
                            {$table}
                        </div>
                     </div>
                </div>


            </div>
        </div></div></div>

    </section>
</div>
<!-- 底部 -->
<include file="Public/common_footer" />
<script src="/Public/admin/jedate/jedate.js"></script>
<link rel="stylesheet" href="/Public/admin/jedate/jedate.css" />
<script>
    initevents();
    function initevents() {
        var stype =$('#select_type').val();
        $('#isOrderChange').val(stype);
        if($('#select_type').val() == 'createtime'){
            $('.isOrderChangeDate').show();
            $('#search_val').hide();
        }
    }
    function showSelectType(o) {
        var _self =$(o);
        var cval = _self.val();
        $('#select_type').val(cval);
        if(cval =='createtime'){
            $('.isOrderChangeDate').show();
            $('#search_val').hide();
        }
        else {
            $('.isOrderChangeDate').hide();
            $('#search_val').show();
        }
    }


    function setJedate(){
        //不显示秒的解决办法
        var stxt = $("#begin_time").val().trim();
        if(stxt.length == 19){
            $("#begin_time").val(stxt.substr(0, 16));
        }
        var etxt = $("#end_time").val().trim();
        if(etxt.length == 19){
            $("#end_time").val(etxt.substr(0, 16));
        }
        var nowStr = getNowDateStr();
        // 获取当前时间
        var start = {
            dateCell: '#begin_time',
            format: 'YYYY-MM-DD hh:mm',
            //minDate: nowStr + ' 00:00:00',
            festival: false,
            maxDate: '2099-12-31 23:59:59',
            isinitVal:true,
            isTime: true,
            choosefun: function(datas) {
                end.minDate = datas;
            }
        };
        var end = {
            dateCell: '#end_time',
            format: 'YYYY-MM-DD hh:mm',
            //minDate: nowStr + ' 00:00:00',
            festival: false,
            maxDate: '2099-12-31 23:59:59',
            isinitVal:true,
            isTime: true,
            choosefun: function(datas) {
                start.maxDate = datas;
            }
        };
        jeDate(start);
        jeDate(end);
    }
    setJedate();
    $(function(){
        var _status = '{$msg.p}';
        //alert(_status);
        if(_status !='' && _status == 0){
            $('input').attr('disabled','disabled');
        }
    });

    ;!function(){
        $('.suggest').on('click', function(){

            var dataId = $(this).data('id');

            layer.ready(function(){
                layer.open({
                    type: 2,
                    title: '订单管理',
                    fix: false,
                    maxmin: true,
                    shadeClose: true,
                    area: ['1100px', '930px'],
                    content: dataId,
                    end: function(){
                        layer.tips('Hi', '#about', {tips: 1})
                    }
                });
            });
        });
    }();

</script>



<script data-exec-on-popstate>

    $(function () {



        $("#search_form").validate({
            rules: {
                search_val:{
                    required: true,
                    maxlength: 140,
                },

            },
            messages:{
                search_val:{
                    required: "搜索内容不能为空",
                    maxlength: "搜索内容不能超过140个字符"
                }
            },
            submitHandler: function(form){
                form.submit();   //提交表单


            }
        });



        $('.btn-pei').on('click', function(){
            var dataId = $(this).data('id');

            layer.ready(function(){
                layer.open({
                    type: 2,
                    title: '打印订单',
                    fix: false,
                    maxmin: true,
                    shadeClose: true,
                    area: ['1200px', '730px'],
                    content: dataId,
                    end: function(){
                        layer.tips('Hi', '#about', {tips: 1})
                    }
                });
            });
        });

        $('.btn-kd').on('click', function(){
            var dataId = $(this).data('id');

            layer.ready(function(){
                layer.open({
                    type: 2,
                    title: '打印快递单',
                    fix: false,
                    maxmin: true,
                    shadeClose: true,
                    area: ['1200px', '730px'],
                    content: dataId,
                    end: function(){
                        layer.tips('Hi', '#about', {tips: 1})
                    }
                });
            });
        });


        $('.grid-select-all').change(function() {
            if (this.checked) {
                $('.grid-item').prop("checked", true);
            } else {
                $('.grid-item').prop("checked", false);
            }
        });

        $('.batch-delete').on('click', function() {
            var selected = [];
            $('.grid-item:checked').each(function(){
                selected.push($(this).data('id'));
            });

            if (selected.length == 0) {
                return;
            }

            if(confirm("Are you sure to delete this item ?")) {
                $.post('/admin/auth/roles/' + selected.join(), {_method:'delete','_token':'ALpaP7hXZ6s2dnAdE02Z6mUSHPt8RkYbcDRp6rpw'}, function(data){
                    $.pjax.reload('#pjax-container');
                    noty({
                        text: "<strong>Succeeded!</strong>",
                        type:'success',
                        timeout: 1000
                    });
                });
            }
        });
        $('.handle-order').hover(function(){
            $(this).addClass('active');
            $(this).parent().find('.edit-list').addClass('active');



        },function(){
            $(this).removeClass('active');
            $(this).parent().find('.edit-list').removeClass('active');
        })


    });

    $('.edit-list').hover(function(){
        $(this).addClass('active');
        $(this).parent().find('.handle-order').addClass('active');
    },function(){
        $(this).removeClass('active');
        $(this).parent().find('.handle-order').removeClass('active');
     }

    );

    function isSure(order) {

        if(confirm("完成操作会将该订单归档并且不允许再做任何操作【订单完结】，系统默认14天自动完结，确认要执行吗？"))
        {

            $.ajax({
                url:"{:U('orders/finishOrder')}",
                type:'post',
                data:{'order_id':order},
                dataType:'json',
                success:function (data) {
                    if(data.status ==0){
                        alert(data.msg);
                        return false;
                    }else{
                        alert(data.msg);
                        location.reload();
                    }

                },
                error:function (err) {
                    alert('参数错误');
                }

            })

        }
    }
    function ept() {
        $('#eid').submit();
    }


</script>


<script src="/Public/layer/layer.js"></script>
